//定义spu请求接口

import request from '@/utils/request'

enum API {
    SPUINFO = "/admin/product/",  //获取列表数据
    getTrademarkName = "/admin/product/baseTrademark/getTrademarkList", //获取全部品牌名称
    imgList = "/admin/product/spuImageList/", //获取图片列表
    saleAttrList = "/admin/product/spuSaleAttrList/", //获取已有销售列表
    allSaleAttrList = "/admin/product/baseSaleAttrList", //全部销售属性
    //修改已有的SPU
    updateSpu = "/admin/product/updateSpuInfo",
    //添加一个新的SPU
    addSpu = "/admin/product/saveSpuInfo",
    //获取商品属性接口
    reqAttrList = "/admin/product/attrInfoList/",
    //添加sku
    reqAddSku = "/admin/product/saveSkuInfo",
    //查看sku
    lookSku = "/admin/product/findBySpuId/",
    //删除已有SPU
    removeSpu = "/admin/product/deleteSpu/"

}

//获取SPU列表数据
export const reqSpuInfo = (page: number, limit: number, category3Id: string | number) => request.get(API.SPUINFO + `${page}/${limit}?category3Id=${category3Id}`)


//获取全部品牌名称
export const reqTrademarkName = () => request.get(API.getTrademarkName)
//获取图片列表
export const reqImgList = (spuId: number) => request.get(API.imgList + spuId)
//获取已有销售列表
export const reqsaleArrList = (spuId: number) => request.get(API.saleAttrList + spuId)
//获取全部销售属性
export const reqallSaleAttrList = () => request.get(API.allSaleAttrList)
//添加与修改SPU接口
export const reqAddOrUpdateSpu = (data: any) => {
    if (data.id) {
        return request.post(API.updateSpu, data);
    } else {
        return request.post(API.addSpu, data);
    }
}
//获取属性列表
export const reqTrademarkAttrList = (category1Id: string | number, category2Id: string | number, category3Id: string | number) => request.get(API.reqAttrList + `${category1Id}/${category2Id}/${category3Id}`)

//添加sku
export const reqAddSku = (data: any) => request.post(API.reqAddSku, data)
//查看sku
export const reqLookSku = (skuId: number) => request.get(API.lookSku + skuId)
//删除
export const reqRemoveSpu = (spuId: number) => request.delete(API.removeSpu + spuId)